# Copyright (C) Kumo inc. and its affiliates.
# Author: Jeff.li lijippy@163.com
# All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

include(shark_gen_cc)

set(test_shark_files
        test.sk
        test-import.sk
        test-import2.sk
        compat/json-test.sk
)

set(SHARK_INCLUDE_DIRECTORY ${PROJECT_SOURCE_DIR})

set(SHARKC_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_shark")
include_directories("${SHARKC_OUTPUT_DIR}")

# Tell shark_generate_cpp to set --src-prefix to our parent directory. This allows us to pass our
# .sk files relative to this directory, but have their canonical name end up as
# test.sk, test-import.sk, etc.
#get_filename_component(SHARKC_SRC_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY)

shark_gen_cc(test_sk_cpp_files test_sk_h_files
        NAME
        test_shark
        PROTOS
        ${test_shark_files}
        OUTPUT_DIR
        ${SHARKC_OUTPUT_DIR}
        COPY
)

include_directories(${PROJECT_SOURCE_DIR}/build)
kmcmake_cc_test(
        NAME shark_lite_test
        MODULE core
        SOURCES
        common-test.cc
        blob-test.cc
        endian-test.cc
        endian-fallback-test.cc
        layout-test.cc
        any-test.cc
        message-test.cc
        encoding-test.cc
        orphan-test.cc
        serialize-test.cc
        serialize-packed-test.cc
        canonicalize-test.cc
        fuzz-test.cc
        test-util.cc
        ${test_sk_cpp_files}
        ${test_sk_h_files}
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        DEPS
        test_shark
        LINKS
        shark::shark_test_static
        shark::shark_static
        ${KMCMAKE_DEPS_LINK}
)

kmcmake_cc_test(
        NAME shark_test
        MODULE core
        SOURCES
        endian-reverse-test.cc
        capability-test.cc
        membrane-test.cc
        schema-test.cc
        schema-loader-test.cc
        schema-parser-test.cc
        dynamic-test.cc
        stringify-test.cc
        serialize-async-test.cc
        serialize-text-test.cc
        rpc-test.cc
        rpc-twoparty-test.cc
        ez-rpc-test.cc
        compiler/lexer-test.cc
        compiler/type-id-test.cc
        test-util.cc
        compat/json-test.cc
        compat/websocket-rpc-test.cc
        ${test_sk_cpp_files}
        ${test_sk_h_files}
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        DEPS
        test_shark
        LINKS
        shark::sharkc_static
        shark::shark_test_static
        shark::shark_static
        ${KMCMAKE_DEPS_LINK}
)


kmcmake_cc_test(
        NAME evolution_test
        MODULE core
        SOURCES
        compiler/evolution-test.cc
        CXXOPTS
        ${KMCMAKE_CXX_OPTIONS}
        LINKS
        shark::sharkc_static
        shark::shark_test_static
        shark::shark_static
        ${KMCMAKE_DEPS_LINK}
)